import React, { Component } from 'react'
/**
 *
 * @param {组件} WrappedComponent
 * @returns 组件
 * 高阶组件 状态提升
 */
function withControl(WrappedComponent) {
  return class extends Component {
    state = {
      value: '',
    }

    onChange = (e) => {
      console.log('高阶组件', e.target.value)
      this.setState({ value: e.target.value })
    }

    render() {
      const newProps = {
        value: this.state.value,
        onChange: this.onChange,
      }
      return <WrappedComponent {...this.props} {...newProps}></WrappedComponent>
    }
  }
}

export default withControl
